<?php

namespace app\install\service\install;

use app\common\util\base\BaseServer;

class InstallSystemService extends BaseServer
{
    public function __construct($data)
    {
        $this->data = $data;
    }

    protected $data = [];
    public function getInputData()
    {
        return $this->data;
    }

    public function handle()
    {
        $this->createDatabase();
        foreach ($this->observer as $observer) {
            $observer->handle($this);
        }
    }

    public function createDatabase()
    {

        $connect = mysqli_connect($this->data['hostname'],$this->data['username'],$this->data['password'],'',$this->data['hostport']);
        if (!$connect->query(sprintf("use %s", $this->data['database']))){
            $connect->query(sprintf("CREATE DATABASE %s", $this->data['database']));
        }
        $connect->close();
    }
}